package com.qef.com.mmovie.presenter;

import com.avos.avoscloud.AVUser;
import com.qef.com.mmovie.mvp.interactor.loginInteractor;
import com.qef.com.mmovie.net.IGetDataDelegate;
import com.qef.com.mmovie.presenter.contract.LoginContract;
import com.qef.com.mmovie.utils.Constants;

import javax.inject.Inject;

/**
 * Created by guangjiego on 2017/4/14.
 */

public class LoginPresenter extends RxPresenter<LoginContract.View> implements LoginContract.Presenter {
    @Inject
    loginInteractor l;

    @Inject
    LoginPresenter() {
    }

    @Override
    public void login(String username, String pwd) {
        l.login(username, pwd, new IGetDataDelegate<AVUser>() {
            @Override
            public void getDataSuccess(AVUser avUser) {
                mView.showContent(avUser, Constants.LOGIN_ACTION);
            }

            @Override
            public void getDataError(Throwable throwable) {
                mView.error(throwable, Constants.LOGIN_ACTION);
            }
        });

    }

    @Override
    public void register(String username, String pwd) {
        l.register(username, pwd, new IGetDataDelegate<AVUser>() {
            @Override
            public void getDataSuccess(AVUser avUser) {
                mView.showContent(avUser, Constants.REGISTER_ACTION);
            }

            @Override
            public void getDataError(Throwable throwable) {
                mView.error(throwable,Constants.REGISTER_ACTION);
            }
        });
    }
}
